package com.example.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: sms
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-04 10:54
 **/
public class FilterDemo05 implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("FilterDemo05 init");
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
            ServletException {

        // 《代码题》
        // 2、
        //
        // 在网站中页面中的内容是经常发生变化的,因此需要设计一个过滤器,使
        //
        // 访问的jsp页面不进行缓存

        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        System.out.println("jsp 不设置缓存了");
        response.setDateHeader("Expires", 0);
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        // 不缓存要存啥值呢
        System.out.println("FilterDemo05 拦截了 filterDemo1  ");
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("FilterDemo05 destroy");

    }
}
